<template>
  <a-card :bordered="false">
    <a-modal
      :bodyStyle ="{
        'height':'200px',
        'display':'flex',
        'justifyContent': 'center',
        'alignItems': 'center'
      }"
      title="选择转发人"
      :visible="syncModalVisible"
      @cancel="handleCancleCredit"
      @ok="handleCreditOk"
    >
      <a-form-model ref="ruleForm" :model="form" :rules="rules" layout="inline">
        <a-form-model-item label="转发人" prop="execUser">
          <select-person-input
            style="width: 300px;"
            placeholder="请选择转发人"
            v-model="form.execUser" />
        </a-form-model-item>
      </a-form-model>
    </a-modal>
    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        :scroll="{x:'120%'}"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">
        <template slot="status" slot-scope="status">
           <a-badge :status="status | statusTypeFilter" :text="status | statusFilter"/>
        </template>
        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>
        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button
            v-else
            :ghost="true"
            type="primary"
            icon="download"
            size="small"
            @click="downloadFile(text)">
            下载
          </a-button>
        </template>
        <template slot="titleSlot" slot-scope="text">
          <span  v-if="text">
             {{text}}%
          </span>
          <span  v-if="!text">
             -
          </span>
        </template>
        <span slot="action" slot-scope="text, record">
             <a @click="openCreditModal(record)">
               转发任务
            </a>

           <a  @click="handleEditTask(record)">
               任务委托
            </a>
           <a v-if="record.taskTemplateStatus!=2" @click="handleEditTemplate(record)">
               进度模板选择
            </a>
           <a  v-if="record.taskTemplateStatus=='2' && record.task_status!='2'" @click="handleEditNode(record)">
               填报进度
            </a>
        </span>

      </a-table>
    </div>
    <erp-progress-task-modal ref="modalForm" @ok="modalFormOk"></erp-progress-task-modal>
    <erp-progress-assigned-task-modal ref="assignedModalForm" @ok="modalFormOk"></erp-progress-assigned-task-modal>
    <erp-progress-task-node-modal ref="nodeModal" @ok="modalFormOk"></erp-progress-task-node-modal>
  </a-card>
</template>

<script>

  import '@/assets/less/TableExpand.less'
  import { mixinDevice } from '@/utils/mixin'
  import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
  import {DisabledAuthFilterMixin} from '@/mixins/DisabledAuthFilterMixin'
  import ErpProgressTaskModal from './modules/ErpProgressTaskModal'
  import ErpProgressAssignedTaskModal from './modules/ErpProgressAssignedTaskModal'
  import ErpProgressTaskNodeModal from './modules/ErpProgressTaskNodeModal'
  import { getAction, putAction } from '@api/manage';
  import SelectPersonInput from '@/views/scy/components/SelectPersonInput'
  export default {
    name: 'ErpProgressTaskList',
    mixins:[JeecgListMixin, mixinDevice, DisabledAuthFilterMixin],
    components: {
      SelectPersonInput,
      ErpProgressTaskModal,
      ErpProgressTaskNodeModal,
      ErpProgressAssignedTaskModal
    },
    data () {
      return {
        //弹框
        syncModalVisible: false,
        //遮罩
        syncLoading: false,
        /* 排序参数 */
        isorter: {
          column: '',
          order: ''
        },
        // execUser: '',
        id: '',
        description: '任务进度管理页面',
        //表头
        columns:[],
        //列设置
        settingColumns:[],
        // 列定义
        defColumns: [
          {
            title: '序号',
            dataIndex: '',
            key:'rowIndex',
            width:60,
            align:"center",
             ellipsis: true,
            customRender:function (t,r,index) {
              return parseInt(index)+1;
            }
          },
          {
            title:'任务编码',
            align:"center",
            dataIndex: 'taskNo',
             ellipsis: true,
          },
          {
            title:'任务名称',
            align:"center",
            dataIndex: 'taskName',
             ellipsis: true,
          },
          {
            title:'任务级别',
            align:"center",
            dataIndex: 'taskLevel_dictText',
             ellipsis: true,
          },
          {
            title:'任务责任人',
            align:"center",
            dataIndex: 'taskLeading_dictText',
             ellipsis: true,
          },
          {
            title:'指派时间',
            align:"center",
            dataIndex: 'assignTime',
             ellipsis: true,
          },
          {
            title:'复用子进度',
            align:"center",
            dataIndex: 'reuseSubPro_dictText',
             ellipsis: true,
          },
          {
            title:'匹配合同额（元）',
            align:"center",
            dataIndex: 'contractAmount',
             ellipsis: true,
          },
          {
            title:'任务进度',
            align:"center",
            dataIndex: 'taskProgress_dictText',
             ellipsis: true,
            scopedSlots: { customRender: 'titleSlot' }
          },
          {
            title:'预计总工时',
            align:"center",
            dataIndex: 'expectTotalHours',
             ellipsis: true,
          },
          {
            title:'已消耗工时',
            align:"center",
            dataIndex: 'consumedHours',
             ellipsis: true,
          },
          {
            title:'任务模板状态',
            align:"center",
            dataIndex: 'taskTemplateStatus_dictText',
             ellipsis: true,
          },
          {
            title:'任务状态',
            align:"center",
            dataIndex: 'taskStatus_dictText',
            ellipsis: true
          },
          {
            title: '操作',
            dataIndex: 'action',
            align:"center",
            fixed:"right",
            width:220,
            scopedSlots: {
            filterDropdown: 'filterDropdown',
            filterIcon: 'filterIcon',
            customRender: 'action' }
          }
        ],
        url: {
          list: "/api/erp/progress/erpProgressTask/list",
          edit: "/api/erp/progress/erpProgressTask/edit",
          delete: "/api/erp/progress/erpProgressTask/delete",
          deleteBatch: "/api/erp/progress/erpProgressTask/deleteBatch",
          exportXlsUrl: "/api/erp/progress/erpProgressTask/exportXls",
          importExcelUrl: "api/erp/progress/erpProgressTask/importExcel",
        },
        dictOptions:{},
        superFieldList:[],
        disableMixinCreated: true,
        form:{
          execUser:""
        },
        rules: {
          execUser: [{ required: true, message: '请选择人员', trigger: 'change' }],
        },
      }
    },
    created() {
      this.initColumns()
      this.getSuperFieldList();
    },
    computed: {
      importExcelUrl: function(){
        return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
      },
    },
    methods: {
      modalFormOk() {
         let obj = {
           id: this.queryParam.projectTaskId
         }
        this.refreshData(obj)
        this.$emit('refresh')
      },
      handleCreditOk() {
        this.$refs.ruleForm.validate(valid => {
          if (valid) {
            if (!this.url.edit) {
              this.$message.error('请设置url.edit属性!')
              return
            }
            var that = this
            let obj = {
              id: that.id,
              taskExecUser: that.form.execUser,
              taskLeading: that.form.execUser
            }
            putAction(that.url.edit, obj).then(res => {
              if (res.success) {
                this.handleCancleCredit()
                that.$message.success('转发成功')
                that.loadData()
              } else {
                that.$message.warning(res.message)
              }
            })
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      openCreditModal(record) {
        this.syncModalVisible = true
        this.syncLoading = false
        this.id = record.id
      },
      handleCancleCredit() {
        this.syncModalVisible = false
        this.id = ''
      },
      handleEditTemplate: function (record) {
        this.$refs.modalForm.edit(record)
        this.$refs.modalForm.title = '进度模板管理'
        this.$refs.modalForm.disableSubmit = false
      },
      handleEditNode: function (record) {
        this.$refs.nodeModal.edit(record)
        this.$refs.nodeModal.title = '填报进度'
        this.$refs.nodeModal.disableSubmit = false
      },
      handleEditTask: function (record) {
        this.$refs.assignedModalForm.edit(record)
        this.$refs.assignedModalForm.title = '任务委托'
        this.$refs.assignedModalForm.disableSubmit = false
      },
      refreshData(data) {
          this.queryParam.projectTaskId = data.id
          this.loadData()
           this.initColumns()
          this.onClearSelected()

      },
      initDictConfig(){
      },
      getSuperFieldList(){
        let fieldList=[];
        fieldList.push({type:'string',value:'taskNo',text:'任务编码',dictCode:''})
        fieldList.push({type:'string',value:'taskName',text:'任务名称',dictCode:''})
        fieldList.push({type:'string',value:'taskLevel',text:'任务级别',dictCode:'task_level'})
        fieldList.push({type:'string',value:'taskLeading',text:'任务责任人',dictCode:''})
        fieldList.push({type:'datetime',value:'assignTime',text:'指派时间'})
        fieldList.push({type:'string',value:'reuseSubPro',text:'复用子进度',dictCode:''})
        fieldList.push({type:'BigDecimal',value:'contractAmount',text:'匹配合同额（元）',dictCode:''})
        fieldList.push({type:'string',value:'taskProgress',text:'任务进度',dictCode:'YES_OR_NO'})
        fieldList.push({type:'string',value:'expectTotalHours',text:'预计总工时',dictCode:''})
        fieldList.push({type:'string',value:'consumedHours',text:'已消耗工时',dictCode:''})
        fieldList.push({type:'string',value:'taskStatus',text:'任务状态',dictCode:''})
        fieldList.push({type:'string',value:'parentTask',text:'上级任务',dictCode:''})
        fieldList.push({type:'string',value:'isChoiseTemplate',text:'是否选择模板',dictCode:'YES_OR_NO'})
        fieldList.push({type:'string',value:'templateId',text:'进度模板',dictCode:''})
        this.superFieldList = fieldList
      }
    }
  }
</script>
<style scoped>
  @import '~@assets/less/common.less';
</style>
